// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Mapping;

public sealed partial class DenseVectorProperty : IProperty
{
	[JsonInclude, JsonPropertyName("dims")]
	public int? Dims { get; set; }
	[JsonInclude, JsonPropertyName("dynamic")]
	public Elastic.Clients.Elasticsearch.Serverless.Mapping.DynamicMapping? Dynamic { get; set; }
	[JsonInclude, JsonPropertyName("element_type")]
	public string? ElementType { get; set; }
	[JsonInclude, JsonPropertyName("fields")]
	public Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? Fields { get; set; }
	[JsonInclude, JsonPropertyName("ignore_above")]
	public int? IgnoreAbove { get; set; }
	[JsonInclude, JsonPropertyName("index")]
	public bool? Index { get; set; }
	[JsonInclude, JsonPropertyName("index_options")]
	public Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptions? IndexOptions { get; set; }

	/// <summary>
	/// <para>Metadata about the field.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("meta")]
	public IDictionary<string, string>? Meta { get; set; }
	[JsonInclude, JsonPropertyName("properties")]
	public Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? Properties { get; set; }
	[JsonInclude, JsonPropertyName("similarity")]
	public string? Similarity { get; set; }

	[JsonInclude, JsonPropertyName("type")]
	public string Type => "dense_vector";
}

public sealed partial class DenseVectorPropertyDescriptor<TDocument> : SerializableDescriptor<DenseVectorPropertyDescriptor<TDocument>>, IBuildableDescriptor<DenseVectorProperty>
{
	internal DenseVectorPropertyDescriptor(Action<DenseVectorPropertyDescriptor<TDocument>> configure) => configure.Invoke(this);

	public DenseVectorPropertyDescriptor() : base()
	{
	}

	private int? DimsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.DynamicMapping? DynamicValue { get; set; }
	private string? ElementTypeValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? FieldsValue { get; set; }
	private int? IgnoreAboveValue { get; set; }
	private bool? IndexValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptions? IndexOptionsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptionsDescriptor IndexOptionsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptionsDescriptor> IndexOptionsDescriptorAction { get; set; }
	private IDictionary<string, string>? MetaValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? PropertiesValue { get; set; }
	private string? SimilarityValue { get; set; }

	public DenseVectorPropertyDescriptor<TDocument> Dims(int? dims)
	{
		DimsValue = dims;
		return Self;
	}

	public DenseVectorPropertyDescriptor<TDocument> Dynamic(Elastic.Clients.Elasticsearch.Serverless.Mapping.DynamicMapping? dynamic)
	{
		DynamicValue = dynamic;
		return Self;
	}

	public DenseVectorPropertyDescriptor<TDocument> ElementType(string? elementType)
	{
		ElementTypeValue = elementType;
		return Self;
	}

	public DenseVectorPropertyDescriptor<TDocument> Fields(Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? fields)
	{
		FieldsValue = fields;
		return Self;
	}

	public DenseVectorPropertyDescriptor<TDocument> Fields(Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument> descriptor)
	{
		FieldsValue = descriptor.PromisedValue;
		return Self;
	}

	public DenseVectorPropertyDescriptor<TDocument> Fields(Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>> configure)
	{
		var descriptor = new Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>();
		configure?.Invoke(descriptor);
		FieldsValue = descriptor.PromisedValue;
		return Self;
	}

	public DenseVectorPropertyDescriptor<TDocument> IgnoreAbove(int? ignoreAbove)
	{
		IgnoreAboveValue = ignoreAbove;
		return Self;
	}

	public DenseVectorPropertyDescriptor<TDocument> Index(bool? index = true)
	{
		IndexValue = index;
		return Self;
	}

	public DenseVectorPropertyDescriptor<TDocument> IndexOptions(Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptions? indexOptions)
	{
		IndexOptionsDescriptor = null;
		IndexOptionsDescriptorAction = null;
		IndexOptionsValue = indexOptions;
		return Self;
	}

	public DenseVectorPropertyDescriptor<TDocument> IndexOptions(Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptionsDescriptor descriptor)
	{
		IndexOptionsValue = null;
		IndexOptionsDescriptorAction = null;
		IndexOptionsDescriptor = descriptor;
		return Self;
	}

	public DenseVectorPropertyDescriptor<TDocument> IndexOptions(Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptionsDescriptor> configure)
	{
		IndexOptionsValue = null;
		IndexOptionsDescriptor = null;
		IndexOptionsDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Metadata about the field.</para>
	/// </summary>
	public DenseVectorPropertyDescriptor<TDocument> Meta(Func<FluentDictionary<string, string>, FluentDictionary<string, string>> selector)
	{
		MetaValue = selector?.Invoke(new FluentDictionary<string, string>());
		return Self;
	}

	public DenseVectorPropertyDescriptor<TDocument> Properties(Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? properties)
	{
		PropertiesValue = properties;
		return Self;
	}

	public DenseVectorPropertyDescriptor<TDocument> Properties(Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument> descriptor)
	{
		PropertiesValue = descriptor.PromisedValue;
		return Self;
	}

	public DenseVectorPropertyDescriptor<TDocument> Properties(Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>> configure)
	{
		var descriptor = new Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>();
		configure?.Invoke(descriptor);
		PropertiesValue = descriptor.PromisedValue;
		return Self;
	}

	public DenseVectorPropertyDescriptor<TDocument> Similarity(string? similarity)
	{
		SimilarityValue = similarity;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (DimsValue.HasValue)
		{
			writer.WritePropertyName("dims");
			writer.WriteNumberValue(DimsValue.Value);
		}

		if (DynamicValue is not null)
		{
			writer.WritePropertyName("dynamic");
			JsonSerializer.Serialize(writer, DynamicValue, options);
		}

		if (!string.IsNullOrEmpty(ElementTypeValue))
		{
			writer.WritePropertyName("element_type");
			writer.WriteStringValue(ElementTypeValue);
		}

		if (FieldsValue is not null)
		{
			writer.WritePropertyName("fields");
			JsonSerializer.Serialize(writer, FieldsValue, options);
		}

		if (IgnoreAboveValue.HasValue)
		{
			writer.WritePropertyName("ignore_above");
			writer.WriteNumberValue(IgnoreAboveValue.Value);
		}

		if (IndexValue.HasValue)
		{
			writer.WritePropertyName("index");
			writer.WriteBooleanValue(IndexValue.Value);
		}

		if (IndexOptionsDescriptor is not null)
		{
			writer.WritePropertyName("index_options");
			JsonSerializer.Serialize(writer, IndexOptionsDescriptor, options);
		}
		else if (IndexOptionsDescriptorAction is not null)
		{
			writer.WritePropertyName("index_options");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptionsDescriptor(IndexOptionsDescriptorAction), options);
		}
		else if (IndexOptionsValue is not null)
		{
			writer.WritePropertyName("index_options");
			JsonSerializer.Serialize(writer, IndexOptionsValue, options);
		}

		if (MetaValue is not null)
		{
			writer.WritePropertyName("meta");
			JsonSerializer.Serialize(writer, MetaValue, options);
		}

		if (PropertiesValue is not null)
		{
			writer.WritePropertyName("properties");
			JsonSerializer.Serialize(writer, PropertiesValue, options);
		}

		if (!string.IsNullOrEmpty(SimilarityValue))
		{
			writer.WritePropertyName("similarity");
			writer.WriteStringValue(SimilarityValue);
		}

		writer.WritePropertyName("type");
		writer.WriteStringValue("dense_vector");
		writer.WriteEndObject();
	}

	private Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptions? BuildIndexOptions()
	{
		if (IndexOptionsValue is not null)
		{
			return IndexOptionsValue;
		}

		if ((object)IndexOptionsDescriptor is IBuildableDescriptor<Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptions?> buildable)
		{
			return buildable.Build();
		}

		if (IndexOptionsDescriptorAction is not null)
		{
			var descriptor = new Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptionsDescriptor(IndexOptionsDescriptorAction);
			if ((object)descriptor is IBuildableDescriptor<Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptions?> buildableFromAction)
			{
				return buildableFromAction.Build();
			}
		}

		return null;
	}

	DenseVectorProperty IBuildableDescriptor<DenseVectorProperty>.Build() => new()
	{
		Dims = DimsValue,
		Dynamic = DynamicValue,
		ElementType = ElementTypeValue,
		Fields = FieldsValue,
		IgnoreAbove = IgnoreAboveValue,
		Index = IndexValue,
		IndexOptions = BuildIndexOptions(),
		Meta = MetaValue,
		Properties = PropertiesValue,
		Similarity = SimilarityValue
	};
}

public sealed partial class DenseVectorPropertyDescriptor : SerializableDescriptor<DenseVectorPropertyDescriptor>, IBuildableDescriptor<DenseVectorProperty>
{
	internal DenseVectorPropertyDescriptor(Action<DenseVectorPropertyDescriptor> configure) => configure.Invoke(this);

	public DenseVectorPropertyDescriptor() : base()
	{
	}

	private int? DimsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.DynamicMapping? DynamicValue { get; set; }
	private string? ElementTypeValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? FieldsValue { get; set; }
	private int? IgnoreAboveValue { get; set; }
	private bool? IndexValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptions? IndexOptionsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptionsDescriptor IndexOptionsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptionsDescriptor> IndexOptionsDescriptorAction { get; set; }
	private IDictionary<string, string>? MetaValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? PropertiesValue { get; set; }
	private string? SimilarityValue { get; set; }

	public DenseVectorPropertyDescriptor Dims(int? dims)
	{
		DimsValue = dims;
		return Self;
	}

	public DenseVectorPropertyDescriptor Dynamic(Elastic.Clients.Elasticsearch.Serverless.Mapping.DynamicMapping? dynamic)
	{
		DynamicValue = dynamic;
		return Self;
	}

	public DenseVectorPropertyDescriptor ElementType(string? elementType)
	{
		ElementTypeValue = elementType;
		return Self;
	}

	public DenseVectorPropertyDescriptor Fields(Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? fields)
	{
		FieldsValue = fields;
		return Self;
	}

	public DenseVectorPropertyDescriptor Fields<TDocument>(Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument> descriptor)
	{
		FieldsValue = descriptor.PromisedValue;
		return Self;
	}

	public DenseVectorPropertyDescriptor Fields<TDocument>(Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>> configure)
	{
		var descriptor = new Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>();
		configure?.Invoke(descriptor);
		FieldsValue = descriptor.PromisedValue;
		return Self;
	}

	public DenseVectorPropertyDescriptor IgnoreAbove(int? ignoreAbove)
	{
		IgnoreAboveValue = ignoreAbove;
		return Self;
	}

	public DenseVectorPropertyDescriptor Index(bool? index = true)
	{
		IndexValue = index;
		return Self;
	}

	public DenseVectorPropertyDescriptor IndexOptions(Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptions? indexOptions)
	{
		IndexOptionsDescriptor = null;
		IndexOptionsDescriptorAction = null;
		IndexOptionsValue = indexOptions;
		return Self;
	}

	public DenseVectorPropertyDescriptor IndexOptions(Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptionsDescriptor descriptor)
	{
		IndexOptionsValue = null;
		IndexOptionsDescriptorAction = null;
		IndexOptionsDescriptor = descriptor;
		return Self;
	}

	public DenseVectorPropertyDescriptor IndexOptions(Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptionsDescriptor> configure)
	{
		IndexOptionsValue = null;
		IndexOptionsDescriptor = null;
		IndexOptionsDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Metadata about the field.</para>
	/// </summary>
	public DenseVectorPropertyDescriptor Meta(Func<FluentDictionary<string, string>, FluentDictionary<string, string>> selector)
	{
		MetaValue = selector?.Invoke(new FluentDictionary<string, string>());
		return Self;
	}

	public DenseVectorPropertyDescriptor Properties(Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? properties)
	{
		PropertiesValue = properties;
		return Self;
	}

	public DenseVectorPropertyDescriptor Properties<TDocument>(Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument> descriptor)
	{
		PropertiesValue = descriptor.PromisedValue;
		return Self;
	}

	public DenseVectorPropertyDescriptor Properties<TDocument>(Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>> configure)
	{
		var descriptor = new Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>();
		configure?.Invoke(descriptor);
		PropertiesValue = descriptor.PromisedValue;
		return Self;
	}

	public DenseVectorPropertyDescriptor Similarity(string? similarity)
	{
		SimilarityValue = similarity;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (DimsValue.HasValue)
		{
			writer.WritePropertyName("dims");
			writer.WriteNumberValue(DimsValue.Value);
		}

		if (DynamicValue is not null)
		{
			writer.WritePropertyName("dynamic");
			JsonSerializer.Serialize(writer, DynamicValue, options);
		}

		if (!string.IsNullOrEmpty(ElementTypeValue))
		{
			writer.WritePropertyName("element_type");
			writer.WriteStringValue(ElementTypeValue);
		}

		if (FieldsValue is not null)
		{
			writer.WritePropertyName("fields");
			JsonSerializer.Serialize(writer, FieldsValue, options);
		}

		if (IgnoreAboveValue.HasValue)
		{
			writer.WritePropertyName("ignore_above");
			writer.WriteNumberValue(IgnoreAboveValue.Value);
		}

		if (IndexValue.HasValue)
		{
			writer.WritePropertyName("index");
			writer.WriteBooleanValue(IndexValue.Value);
		}

		if (IndexOptionsDescriptor is not null)
		{
			writer.WritePropertyName("index_options");
			JsonSerializer.Serialize(writer, IndexOptionsDescriptor, options);
		}
		else if (IndexOptionsDescriptorAction is not null)
		{
			writer.WritePropertyName("index_options");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptionsDescriptor(IndexOptionsDescriptorAction), options);
		}
		else if (IndexOptionsValue is not null)
		{
			writer.WritePropertyName("index_options");
			JsonSerializer.Serialize(writer, IndexOptionsValue, options);
		}

		if (MetaValue is not null)
		{
			writer.WritePropertyName("meta");
			JsonSerializer.Serialize(writer, MetaValue, options);
		}

		if (PropertiesValue is not null)
		{
			writer.WritePropertyName("properties");
			JsonSerializer.Serialize(writer, PropertiesValue, options);
		}

		if (!string.IsNullOrEmpty(SimilarityValue))
		{
			writer.WritePropertyName("similarity");
			writer.WriteStringValue(SimilarityValue);
		}

		writer.WritePropertyName("type");
		writer.WriteStringValue("dense_vector");
		writer.WriteEndObject();
	}

	private Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptions? BuildIndexOptions()
	{
		if (IndexOptionsValue is not null)
		{
			return IndexOptionsValue;
		}

		if ((object)IndexOptionsDescriptor is IBuildableDescriptor<Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptions?> buildable)
		{
			return buildable.Build();
		}

		if (IndexOptionsDescriptorAction is not null)
		{
			var descriptor = new Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptionsDescriptor(IndexOptionsDescriptorAction);
			if ((object)descriptor is IBuildableDescriptor<Elastic.Clients.Elasticsearch.Serverless.Mapping.DenseVectorIndexOptions?> buildableFromAction)
			{
				return buildableFromAction.Build();
			}
		}

		return null;
	}

	DenseVectorProperty IBuildableDescriptor<DenseVectorProperty>.Build() => new()
	{
		Dims = DimsValue,
		Dynamic = DynamicValue,
		ElementType = ElementTypeValue,
		Fields = FieldsValue,
		IgnoreAbove = IgnoreAboveValue,
		Index = IndexValue,
		IndexOptions = BuildIndexOptions(),
		Meta = MetaValue,
		Properties = PropertiesValue,
		Similarity = SimilarityValue
	};
}